﻿using AutoMapper;
using QuanLyGiaoVuDAL.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuanLyGiaoVuUI.Models.TaiLieu
{
    public class DanhSachTaiLieuViewModel
    {
        public System.Guid MaTaiLieu { get; set; }

        public string TenTaiLieu { get; set; }

        public string TenTapTin { get; set; }

        public string PhanMoRong { get; set; }

        public System.Guid MaTapTin { get; set; }

        public long? KichThuoc { get; set; }

        public System.Guid MaLoaiTaiLieu { get; set; }

        public System.Guid MaThuMuc { get; set; }

        public System.Nullable<int> Diem { get; set; }

        public bool DaKiemDuyet { get; set; }

        public bool DaXoa { get; set; }

        public bool ChiaSe { get; set; }

        public string GhiChu { get; set; }

        public LoaiTaiLieuDTO LoaiTaiLieu { get; set; }

        public static DanhSachTaiLieuViewModel FromTaiLieuDTO(TaiLieuDTO taiLieu)
        {
            Mapper.CreateMap(typeof(TaiLieuDTO), typeof(DanhSachTaiLieuViewModel));
            DanhSachTaiLieuViewModel viewModel = new DanhSachTaiLieuViewModel();
            Mapper.Map(taiLieu, viewModel);
            return viewModel;
        }

        public static IEnumerable<DanhSachTaiLieuViewModel> FromTaiLieuDTOList(IEnumerable<TaiLieuDTO> taiLieuDTOList)
        {
            List<DanhSachTaiLieuViewModel> taiLieuViewModelList = new List<DanhSachTaiLieuViewModel>();
            foreach (TaiLieuDTO taiLieuDTO in taiLieuDTOList)
            {
                taiLieuViewModelList.Add(DanhSachTaiLieuViewModel.FromTaiLieuDTO(taiLieuDTO));
            }
            return taiLieuViewModelList.AsEnumerable<DanhSachTaiLieuViewModel>();
        }
    }
}